/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.wholeconsulting.pacc.gui.utils.treetable.modelos;

import ar.com.wholeconsulting.pacc.gui.utils.treetable.TreeTableNode;
import ar.com.wholeconsulting.pacc.model.Fabricante;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;

/**
 *
 * @author pable
 */
public class ModelosTreeTableSelectionListener implements TreeSelectionListener {

    List<JComponent> components = new ArrayList<JComponent>();


    public ModelosTreeTableSelectionListener(JComponent... components) {
        this.components=Arrays.asList(components);
    }



    @Override
    public void valueChanged(TreeSelectionEvent e) {
        TreePath path = e.getPath();
        Object obj = path.getLastPathComponent();
        if (obj instanceof TreeTableNode) {
            if (((TreeTableNode) obj).getObj() instanceof Fabricante) {
                for(JComponent component : components){
                    component.setEnabled(false);
                }
            } else {
                for(JComponent component : components){
                    component.setEnabled(true);
                }
            }
        }
    }
}
